package com.briup.day25.Set;

import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo1 {
	
	public static void main(String[] args) {
		Set set = new TreeSet();
		Teacher t1 = new Teacher(1001,"张3",23,20000);
		Teacher t2 = new Teacher(1002,"张4",26,20000);
		Teacher t3 = new Teacher(1003,"张5",25,20000);
		set.add(t1);
		set.add(t3);
		set.add(t2);
		
		System.out.println(set.size());
		
		set.forEach(System.out::println);
	}

}

 class Teacher implements Comparable{  // 教师类
	
    public int id;			// 属性【工号】
    public String name;		// 属性【姓名】
    public int age;			// 属性【年龄】
    public double salary;	// 属性【工资】
	
    public Teacher(int id, String name, int age, double salary) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.salary = salary;
	}
    
    public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}

	@Override
	public String toString() {
		return "Teacher [id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + "]";
	}

	@Override
	public int compareTo(Object o) {
		//<0，插左边    >0，右边     0不插
		
		System.out.println("compare to..."+this.name+" ," + ((Teacher)o).name);
		
		//按照id升序   this o比  
		Teacher t = (Teacher) o;
		
		/*if (this.age > t.age) {
			return 1;
		}else {
			return -1;
		}*/
		
		//return this.age > t.age ? 1 : -1;
		
		//return this.age - t.age;
		
		//返回随机正数负数
		int r1 = (int) (Math.random() * 1000);
		int r2 = (int) (Math.random() * 1000);
		System.out.println(r1 - r2);
		return r1 - r2;
		
		
		
	}
    


}
